<template>
  <div class="app-container hk-flex-column">

    <search-form
      :data="queryParams"
      :field-list="filterInfo.fieldList"
      :list-type-info="dictList"
      @handleSearch="handleQuery"
      @handleReset="resetQuery"
    />
    <el-row>
      <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd">新增</el-button>
          <el-button size="small" @click="importTemplate">下载模板</el-button>
      <el-button size="small" @click="handleImport">导入</el-button>
      <el-button size="small" @click="handleExport">导出查询结果</el-button>
    </el-row>

    <hk-table
      :table-data="tableData"
      :table-columns="tableList"
      :selection="false"
      :show-index="true"
      :total="total"
      :loading="loading"
      :table-height="80"
      operate
      operate-width="180"
      :query-params="queryParams"
      @handleSelectionChange="handleSelectionChange"
      @changePage="getDataList"
    >
      <!-- 操作权限 -->
      <template #operate="scope">

        <el-button
          size="mini"
          type="text"
          @click="handleEdit(scope.row)"
        >编辑</el-button>
        <el-button
          size="mini"
          type="text"
          @click="handleDelete(scope.row)"
        >删除</el-button>
      </template>
    </hk-table>
    <bm-drawer ref="post_drawer" :dict-list="dictList" :title="title" @handleSubmit="getDataList" />
    <hk-upload ref="import_dia" :url="url" title="导入" :accept="accept" @submit="getDataList" />
  </div>
</template>

<script>
import { pageList, deleteItem } from '@/api/specialProject/bmItem'
import SearchForm from '@/components/HkSearchform/index.vue'
import HkTable from '@/components/Hk-Table/index.vue'
import bmDrawer from './components/bmDrawer.vue'
export default {
  components: {
    SearchForm,
    HkTable,
    bmDrawer
  },
  data() {
    return {
      queryParams: {
        current: 1,
        size: 10
      },
      url: window.baseUrl.action + '/trainRecord/import',
      title: '导入BM培训记录',
      accept: '.xlsx',
      checkedList: [],
      tableData: [],
      total: 0,
      loading: false,
      tableList: [
        { label: '保密培训名称', param: 'trainName' },
        { label: '培训简介', param: 'trainDesc' },
        { label: '时间', param: 'trainTime' },
        { label: '参与人员数量', param: 'userCount' }

      ],
      filterInfo: {
        fieldList: [
          { label: '关键字', type: 'input', field: 'keyword', placeholder: '请输入培训名称', maxlength: 20 },
          { label: '时间', type: 'dateRange', field: 'time' }
        ]
      },
      dictList: {
        secLevelList: []
      }
    }
  },
  mounted() {
    this.getDataList()
    // this.getTypes()
  },
  methods: {
    //  查询
    handleQuery() {
      this.queryParams.current = 1
      this.getDataList()
    },
    //  重置
    resetQuery() {
      this.queryParams.current = 1
      this.queryParams.size = 10
      this.getDataList()
    },
    getTypes() {
      // listByType('secLevel').then(res => {
      //   this.dictList.secLevelList = res.map(i => {
      //     return {
      //       label: i.dictValue,
      //       value: i.dictKey
      //     }
      //   })
      // })
    },
    getDataList(val) {
      this.queryParams = { ...this.queryParams, ...val }
      this.loading = true

      this.queryParams.startTime = this.queryParams.time?.[0]
      this.queryParams.endTime = this.queryParams.time?.[1]

      pageList(this.queryParams).then(res => {
        this.loading = false
        this.tableData = res.list
        this.total = res.total
      })
    },
    handleSelectionChange(obj) {
      this.checkedList = obj
    },

    handleAdd() {
      this.title = '新增'
      this.$refs.post_drawer.show()
    },
    handleEdit(row) {
      this.title = '编辑'
      this.$refs.post_drawer.show(row.id)
    },
    handleSubmit() {},
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id
      this.$modal
        .confirm('是否确认删除所选数据项？')
        .then(function() {
          return deleteItem(id)
        })
        .then(() => {
          this.$modal.msgSuccess('删除成功')
          this.getDataList()
        })
        .catch(error => {
          console.log(error)
        })
    },
    /** 下载模板操作 */
    importTemplate() {
      this.smDownload(window.baseUrl.action + '/trainRecord/template', {}, `保密培训记录导入模板.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.$refs.import_dia.show()
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        window.baseUrl.action + '/trainRecord/export',
        {
          ...this.queryParams
        },
        `BM培训记录${new Date().getTime()}.xlsx`,
        'daochu'

      )
    }
  }
}
</script>

  <style lang="scss" scoped>

  .el-row{
    position: absolute;
    right: 20px;
    top: 50px;
  }
  .total-title {
    margin-bottom: 15px;
    margin-top: 6px;
    line-height: 24px;
  }
  .font-size16 {
    font-size: 16px;
  }
  .flex-1 {
    flex: 1;
    justify-content: space-between;
    height: 100%;
  }
  .font-c-blue {
    color: #4b6eef;
    font-size: 36px;
  }
  .mt-20 {
    margin-top: 20px;
  }
  ::v-deep{
    .content{
      padding-bottom: 0;
    }
  }
  </style>

